import datetime

# 两个datetime.date类型相减
# today = datetime.date(2021, 3, 9)
# yesterday = datetime.date(2021, 3, 8)
# delta = today - yesterday
# time1 = datetime.datetime.now()

# 两个datetime.datetime类型相减
# time_start = datetime.datetime.now()
# time_end = datetime.datetime.now()
# delta = time_end - time_start
# print(delta.total_seconds())

# 构造datimedelta
# time_start = datetime.datetime.now()
# delta = datetime.timedelta(days=5)
# time_end = time_start + delta
# print(time_start, '\r\n', time_end)


# 计算日期返回文本
def get_date(days):
    """计算日期"""
    today = datetime.date.today() # 当前日期
    delta = datetime.timedelta(days=days) # 间隔天数
    calc_date = today + delta # 计算日期
    format_date = calc_date.strftime('%Y-%m-%d') # 格式化为文本
    return format_date # 函数返回值


if __name__ == '__main__':
    date = get_date(-2)
    print(datetime.date.today())
    print(date)
